package approvalDao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: LYZ
 * \* Date: 2022/2/19
 * \* Time: 17:57
 * \* Description:
 * \
 */
public class ViewUsers {
    Connection connection = ConnectionFactory.getConnection();
    Statement statement = null;
    ResultSet resultSet = null;
    List<Information> InformationList = new ArrayList<>();
    Information information = null;


    String sql = "select * from borrowusers where status='待审批'";
    public List viewList() throws SQLException {
        //连接数据库
        try {
            statement = connection.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            resultSet = statement.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //遍历查询结果
        while(resultSet.next()){
            //查询数据库，将信息录入list集合
            information = new Information();
            information.setBookName(resultSet.getString("bookName"));
            information.setUserName(resultSet.getString("userName"));
            information.setBorrowDate(resultSet.getString("borrowDate"));
            information.setBackDate(resultSet.getString("backDate"));
            information.setEmail(resultSet.getString("email"));
            information.setStatus(resultSet.getString("status"));
            InformationList.add(information);
        }

        //关闭连接
        resultSet.close();
        statement.close();
        connection.close();

        return InformationList;

    }
}

